//
//  DataBaseHandel.m
//  OFootball
//
//  Created by Hauler Lord on 15/9/23.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "DataBaseHandel.h"

@implementation DataBaseHandel


+(instancetype)shareBaseData
{
    static DataBaseHandel *data = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        data = [[DataBaseHandel alloc] init];
        data.dataText = [NSString string];
        data.dataPic = [NSMutableArray array];
        data.nickName = [NSString string];
    });
    return data;
}



//上传图片
-(void)upLoadImage:(UIImage *)image andImageName:(NSString *)imageName andUrl:(NSString *)url
{
    
    //创建管理
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //存放非文件参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:@"动次打次" forKey:@"nick"];
    [params setObject:@"0" forKey:@"sex"];
    [params setObject:@"动次打次" forKey:@"signature"];
    
    //发送请求
    
    
    
    NSLog(@"imagename == %@",imageName);
    [manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        //        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        //        formatter.dateFormat = @"yyyyMMddHHmmss";
        //        NSString *str = [formatter stringFromDate:[NSDate date]];
        //        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
        
        NSData *fileData = UIImageJPEGRepresentation(image, 1.0);
        
        [formData appendPartWithFileData:fileData name:@"headFile" fileName:imageName mimeType:@"image/jpeg"];
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"上传成功");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"上传失败 ");
    }];
    
}





@end
